import { ref } from 'vue';

import pageSearch from '@/components/page-search.vue';
import pageContent from '@/components/page-content.vue';
import pageModal from '@/components/page-modal.vue';

const usepageHook = () => {
  const pageContentRef = ref<InstanceType<typeof pageContent>>();
  const pageModalRef = ref<InstanceType<typeof pageModal>>()

  const handleQuery = (pageName: string, payload: any) => {
    pageContentRef.value?.getpageTableList(pageName, payload);
  };

  const handleRest = (pageName: string) => {
    pageContentRef.value?.getpageTableList(pageName);
  };

  const handleAdd = () => {
    pageModalRef.value?.handleChange(true);
  };

  const handleEdit = (modalInfo: any) => {
    pageModalRef.value?.handleChange(false, modalInfo);
  };

  return {
    pageSearch,
    pageContent,
    pageModal,
    handleQuery,
    handleRest,
    handleAdd,
    handleEdit,
    pageContentRef,
    pageModalRef
  };
};

export default usepageHook;
